package com.llj.chatbidemo.config;

import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Component;

import java.sql.SQLException;

@Component
public class MetadataHolder {
    private JSONObject metadata; // Fastjson类型
    private final MetadataCollector service;

    // 获取最新元数据（线程安全）
    public JSONObject getMetadata() {
        return metadata;
    }
    public MetadataHolder(MetadataCollector collector) throws SQLException {
        this.service = collector;
        refresh(); // 启动时立即加载
    }


    // 可选的定时刷新（例如每天凌晨更新）
    //@Scheduled(cron = "0 0 0 * * ?")
    public void refresh() throws SQLException {
        JSONObject jsonNode = service.generateMetadata();
        this.metadata = jsonNode;
    }
}

